package com.example.photoview;

import javafx.scene.control.Alert;

import java.util.ArrayList;

/**
 * 完成图片压缩功能
 */
public class CompressAction {
    private HomeController hc = (HomeController) ControllerUtil.controllers.get(HomeController.class.getSimpleName());
    ArrayList<ImageModel> sourceList = SelectionModel.getImageModels();//存放图片本身的List
    public CompressAction(ImageBox imageBox){
        if(sourceList.isEmpty()){
            SelectedModel.setSourcePath(imageBox.getImageModel().getImageFilePath());
        }else{
            SelectedModel.setSourcePath(sourceList);
        }
        int success = SelectedModel.compressImage(200);
        hc.refreshImagesList(hc.getSortComboBox().getValue());
        if(success!=0){
            Alert alert=new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("压缩信息");
            alert.setHeaderText(null);
            alert.setContentText("已压缩" + success + "张图片并创建副本");
            alert.showAndWait();
        }else{
            Alert alert=new Alert(Alert.AlertType.ERROR);
            alert.setTitle("压缩错误");
            alert.setHeaderText(null);
            alert.setContentText(" 该图片不符合压缩条件 \n压缩条件:大于200KB");
            alert.showAndWait();
        }
    }
}
